package com.qxsx.midi.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.qxsx.midi.R;
import com.qxsx.midi.model.Address;
import com.qxsx.midi.model.Category;
import com.qxsx.midi.model.ClassVideo;

import java.util.List;

/**
 * Created by Joney on 2015/8/31.
 */
public class AddressAdapter extends BaseAdapter {


    private Context context;

    private List<Address> lists;

    private int mChoose ;

    public AddressAdapter(Context context, List<Address> lists) {
        this.context = context;
        this.lists = lists;
        mChoose = lists.size()-1;
    }

    @Override
    public int getCount() {
        return lists.size();
    }

    @Override
    public Object getItem(int position) {
        return lists.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public void setChoose(int choose) {
        mChoose = choose;
        notifyDataSetChanged();
    }

    //动态添加数据
    public void addData(List<Address> addlist) {//刷新数据
        for (Address address : addlist) {
            lists.add(address);
        }
        notifyDataSetChanged();
    }
    // 清空所有
    public void removeAll()
    {
        lists.clear();
        notifyDataSetChanged();
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = convertView.inflate(context, R.layout.exam_address_item, null);
            holder = new ViewHolder();
            holder.tv_desc = (TextView) convertView.findViewById(R.id.tv_desc);
            holder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            convertView.setTag(holder);

        } else {
            holder = (ViewHolder) convertView.getTag();

        }

        final  Address address = lists.get(position);
        holder.tv_name.setText(address.getAd_name());
        holder.tv_desc.setText(address.getAd_address());



        return convertView;
    }


    private class ViewHolder {
        TextView tv_desc;
        TextView tv_name;
    }
}

